In [1]:
# Set up our notebook environment.
% matplotlib inline
import matplotlib as mpl
import numpy as np
import pandas as pd
import sys
sys.path.append('../')
import os
# For interacting with the flask-mongoengine ODM. TODO: necessary?
os.environ['CONFIG_FILE'] = 'conf/default.cfg'
# This directory is in the .gitignore
SAVE_DIR = 'Figures'
if not os.path.isdir(SAVE_DIR):
os.mkdir(SAVE_DIR)
from projects.common import get_project_data_frame
# TODO: incorporate this fit_all_networks into projects.common
# from viomet_9_10_17 import (
# fit_all_networks, by_network_frequency_figure,
# subject_object_analysis, by_facet_word
# )
from projects.viomet.analysis import fit_all_networks
from projects.viomet.vis import by_network_frequency_figure
In [2]:
# Fetch the processed .csv from metacorps.io and inspect the dataframe.
metaphors_url = \
'http://metacorps.io/static/data/viomet-2012-snapshot-project-df.csv'
viomet_df = get_project_data_frame(metaphors_url)
viomet_df.head()
Out[2]:
In [3]:
date_range = pd.date_range('2012-9-1', '2012-11-30', freq='D')
# Run modeling fits to determine the first and last date of the
# excited state for each of the three networks MSNBC, CNN, and Fox News.
IATV_CORPUS_NAME = 'Viomet Sep-Nov 2012'
fit_networks = fit_all_networks(
viomet_df,
date_range=date_range,
iatv_corpus_name=IATV_CORPUS_NAME # TODO: why is this here?
)
# Fit a model to the aggregation over
# agg =
In [4]:
fit_networks
Out[4]:
In [5]:
# The fit_networks dictionary printed above
# contains more information than we need
# at this time. Here we extract what we do need.
partition_infos = {network: fit_networks[network][0]
for network in ['MSNBCW', 'CNNW', 'FOXNEWSW']}
from projects.viomet.vis import by_network_frequency_figure
by_network_frequency_figure(
viomet_df, date_range=date_range,
iatv_corpus_name=IATV_CORPUS_NAME,
partition_infos=partition_infos,
save_path='Figures/model_fits_2012.pdf'
)
from IPython.display import IFrame
IFrame('Figures/model_fits_2012.pdf', width=600, height=450)
Out[5]:
In [6]:
# soa_dict = subject_object_analysis(
# viomet_df, subj_obj=[
# ('Romney', 'Obama'),
# ('Obama', 'Romney'),
# ('Romney', None),
# ('Obama', None),
# (None, 'Romney'),
# (None, 'Obama')
# ],
# date_range=date_range,
# plot=True, save_dir=SAVE_DIR, font_scale=1.5
# )
In [7]:
from projects.common.analysis import daily_metaphor_counts
from projects.viomet.analysis import partition_sums
counts = daily_metaphor_counts(viomet_df, date_range, by=['network'])
sums = partition_sums(counts, partition_infos)
display(sums)
This actually is correct, I'm confident. I want to make some separate scripts for doing these analyses, so I can just do python partition_sums.py
and it will create some latex tables automatically.
In [8]:
# from projects.viomet.analysis import partition_info_table
# print(partition_info_table(partition_infos))
In [9]:
# from projects.viomet.analysis import partition_sums
# from projects.common.analysis import daily_metaphor_counts
# import pandas as pd
# dates = pd.date_range('2012-9-1', '2012-11-30', freq='D')
# cdf = daily_metaphor_counts(viomet_df, dates, by=['network'])
# # display(cdf.head())
# display(partition_sums(cdf, partition_infos))
In [10]:
# cdf = daily_metaphor_counts(viomet_df, dates, by=['network', 'facet_word'])
# sums = partition_sums(cdf, partition_infos)